package cn.lijiancn01.demo.system.controller;

import cn.lijiancn01.demo.framework.model.AmisSource;
import cn.lijiancn01.demo.framework.model.R;
import cn.lijiancn01.demo.system.service.TableInfoService;
import cn.lijiancn01.demo.system.vo.TableInfoQueryVO;
import com.google.common.collect.Sets;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

@RestController
@RequestMapping("api")
public class TableInfoController {

    @Autowired
    private TableInfoService tableInfoService;

    @PostMapping("tableinfo/list")
    public R list(@RequestBody TableInfoQueryVO query) {
        Set<String> tables = Sets.newHashSet(query.getTableName().split(","));
        return R.data(tableInfoService.list(tables, null));
    }

    @GetMapping("tableinfo/listSelect")
    public R<AmisSource> listSelect(@Param("dataSourceCode") String dataSourceCode) {
        return R.data(tableInfoService.listSelect(dataSourceCode));
    }
}
